﻿using SD.Toolkits.Mapper;
using SlamDunk.MES.Domain.Entities.QualityContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ExecutionContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.PlanContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.QualityContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ResourceContext;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Maps
{
    /// <summary>
    /// 质量相关映射
    /// </summary>
    public static class QualityMap
    {
        #region # 质量检查映射 —— static QualityInspectionInfo ToDTO(this QualityInspection...
        /// <summary>
        /// 质量检查映射
        /// </summary>
        public static QualityInspectionInfo ToDTO(this QualityInspection inspection)
        {
            QualityInspectionInfo inspectionInfo = inspection.Map<QualityInspection, QualityInspectionInfo>();

            return inspectionInfo;
        }
        #endregion

        #region # 作业计划质量检查映射 —— static ExecutionPlanInspectionInfo ToDTO(this ExecutionPlanInspection...
        /// <summary>
        /// 作业计划质量检查映射
        /// </summary>
        public static ExecutionPlanInspectionInfo ToDTO(this ExecutionPlanInspection inspection, IDictionary<Guid, ExecutionPlanInfo> executionPlanInfos)
        {
            ExecutionPlanInspectionInfo inspectionInfo = inspection.Map<ExecutionPlanInspection, ExecutionPlanInspectionInfo>();
            inspectionInfo.ExecutionPlanInfo = executionPlanInfos?[inspection.ExecutionPlanId];

            return inspectionInfo;
        }
        #endregion

        #region # 工单质量检查映射 —— static WorkOrderInspectionInfo ToDTO(this WorkOrderInspection...
        /// <summary>
        /// 工单质量检查映射
        /// </summary>
        public static WorkOrderInspectionInfo ToDTO(this WorkOrderInspection inspection, IDictionary<Guid, ExecutionPlanInfo> executionPlanInfos, IDictionary<Guid, WorkOrderInfo> workOrderInfos)
        {
            WorkOrderInspectionInfo inspectionInfo = inspection.Map<WorkOrderInspection, WorkOrderInspectionInfo>();
            inspectionInfo.ExecutionPlanInfo = executionPlanInfos?[inspection.ExecutionPlanId];
            inspectionInfo.WorkOrderInfo = workOrderInfos?[inspection.WorkOrderId];

            return inspectionInfo;
        }
        #endregion

        #region # 质量检查明细映射 —— static QualityInspectionDetailInfo ToDTO(this QualityInspectionDetail...
        /// <summary>
        /// 质量检查明细映射
        /// </summary>
        public static QualityInspectionDetailInfo ToDTO(this QualityInspectionDetail detail, IDictionary<Guid, MaterialInfo> productInfos)
        {
            QualityInspectionDetailInfo detailInfo = detail.Map<QualityInspectionDetail, QualityInspectionDetailInfo>();
            detailInfo.ProductInfo = productInfos?[detail.ProductId];

            return detailInfo;
        }
        #endregion
    }
}
